import { Injectable, Signal, signal } from '@angular/core';
import { AbsInfoService, Info } from './interface';

@Injectable({
  providedIn: 'root',
})
export class SuccessInfoService extends AbsInfoService {
  registry = signal<Info[]>([]);
  override readonly all: Signal<Info[]> = this.registry.asReadonly();

  constructor() {
    super();
  }

  override record(info: Info): void {
    if (info.type === 'success') {
      this.registry.update((r) => {
        r.push(info);
        return r;
      });
    }
  }
}
